/**
 * 跳转页面处理器
 */

import tools from "./tools";
import StorageKeys from '@/common/const/StorageKeys'
/**
 * 方法名:
 *     '1':	'redCloudNewsDetail', // 新闻
       '2':	'url', // 外部链接
       '3':	'oneAnswerEveryday', // 筑学习
       '4':	'applicationList', // 红友好友申请
       '5':	'videoDetail', // 课件点播
       '6':	'audioDetail', // 红云FM
       '7':	'groupInfoList', // 组工信息
       '8':	'workingTrends', // 筑固工程-动态
       '9':	'demonstration', // 筑固工程-示范带
       '10':	'onlineObservation', // 筑固工程-示范点
       '11':	'observe', // 筑固工程-线上观摩
       '12':	'policyDocument', // 党务知识
       '13':	'noticeNoticeDetail', // 通知公告
       '14':	'sanhuiyikeDetail', // 三会一课
       '15':	'sanhuiyikeDetail', // 主题党日
       '16':	'sanhuiyikeDetail', // 民主评议
       '17':	'newTermReminderDetail', // 换届提醒
       '18':	'branchSpace', // 支部空间
       '19':  'notifyDetail', //更新通知
       '20':  'noticeNew', // 首页通知
 * 入参有$router、businessId
 *
 * test/index.vue 为单元测试入口，每个跳转均需编写单元测试
 */
/*获取角色权限*/
function getRole() {
  let userInfo = this.$localStorage.get('userInfo')
  if (userInfo.type === "10") {
    return false;
  } else {
    return true;
  }
}
/*1 新闻 红云头条*/
function redCloudNewsDetail ($router, businessId) {
  $router.push({name: 'redCloudNewsDetail', params:{
    id: businessId
  }})
}
/*2 外部链接*/
function url ($router, businessId) {
  if (window.android && window.android.openUrlAdapt) {
    window.android.openUrlAdapt(businessId,1)
  }
}
/*3 筑学习*/
function oneAnswerEveryday ($router, businessId) {
  if (!getRole()) {
    return tools.tip("你没有权限访问");
  }
  this.$store.state.oneAnswerFrom = true;
  $router.push({name: `oneAnswerEveryday`});
}
/*4 红友好友申请*/
function applicationList ($router, businessId) {
  $router.push({ name: `applicationList` , params: {index:1}});
}
/*5 课件点播*/
function videoDetail ($router, businessId) {
  this.fetchService.contentDetailNew(businessId).then(res=>{
    if (res.code == 0 ) {

      this.$store.state.isVideo = true
      this.$store.state.videoDetail = res.data.newsContent
      this.$store.state.newsDetail = res.data.newsContent
    }
    $router.push({name: 'videoDetail',  query: {id: businessId, zhuanji: 1}})
  })
}
/*6 红云FM*/
function audioDetail ($router, businessId) {
  // this.fetchService.contentDetailNew(businessId).then( (res)=> {
  this.fetchService.contentPageDetail(businessId).then( (res)=> {
    if (res.code == 0) {
      this.$store.state.isVideo = false
      this.$store.state.videoDetail = res.data.newsContent
      this.$store.state.newsDetail = res.data.newsContent
      $router.push({name: 'videoDetail',  query: {id: businessId, zhuanji: 1}})
    }

  })
}
/*7 组工信息*/
function groupInfoList ($router, businessId) {
  // $router.push({name: 'groupInfoDetail', query: {id: businessId}})
  this.$store.commit('addRoute','groupInfoList')
  $router.push({name: 'groupInfoList'})
}
/*8 筑固工程-动态*/
function workingTrends ($router, businessId) {

    $router.push({name: 'redCloudNewsDetail',   params:{
        id: businessId,title: '动态'}})
}
/*9 筑固工程-示范带*/
function demonstration ($router, businessId) {
  $router.push({name: 'redCloudNewsDetail',   params:{
      id: businessId,title: '示范带'}})
}
/*10 筑固工程-示范点*/
function onlineObservation ($router, businessId) {
  $router.push({name: 'onlineObservation', params:{title: '现场会导览'}})
}
/*11 筑固工程-线上观摩*/
function observe ($router, businessId) {
  this.$store.state.workingTrends_tabIndex = 3;
  $router.push({name: 'workingTrends'})
}
/*12 党务知识 */
function policyDocument ($router, businessId) {
  $router.push({name: 'policyActivityDetail', query: {id: businessId, flag: 3}})
}
/*13 通知公告 */
function noticeNoticeDetail ($router, businessId) {
  let userInfo = this.$localStorage.get('userInfo')
  this.$store.state.showFeedback = true
  let data = {
    msgId: businessId,
  };
  let params1 ={
    businessId: businessId,
    isRead: "1",
    recUserId: userInfo.id
  }
  this.fetchService.optNodeMsgRead(data).then((res) => {});//调用党务的已读
  this.fetchService.updateReadByBusinessId(params1).then((res) => {});//调用首页的已读
  $router.push({
    path: `/noticeNoticeDetail/${businessId}/0`,
  });
}
/*14 三会一课 15 主题党日 16 民主评议*/
function sanhuiyikeDetail ($router, businessId) {
  $router.push({
    path: `/sanhuiyikeDetail/${businessId}`,query:{fromType: 'shyk'}
});
  /*let data = {
    msgId: businessId,
  };
  this.fetchService.optNodeMsgRead(data).then((res) => {});
  $router.push({
    path: `/noticeNoticeDetail/${businessId}/0`,
  });*/
}
/*15 主题党日 */
/*function sanhuiyikeDetail ($router, businessId) {
  this.$router.push({
    path: `/sanhuiyikeDetail/${businessId}?fromType=ztdr`,
  });
}*/
/*16 民主评议 */
/*function sanhuiyikeDetail ($router, businessId) {
  this.$router.push({
    path: `/sanhuiyikeDetail/${businessId}?fromType=mzpy`,
  });
}*/
/*17 换届提醒 */
function newTermReminderDetail ($router, businessId) {
  this.$router.push({
    path: `/newTermReminderDetail`,
  });
}
/*18 支部空间 */
function branchSpace ($router, businessId) {
  let memorabiliaData = this.$localStorage.get(StorageKeys.MEMORABILIA_DATA)
  this.$router.push({
    path: `/branchSpace/${memorabiliaData.id}`,
  });
}
/*19 更新通知*/
function notifyDetail ($router, businessId) {
  $router.push({name: 'notifyDetail', params:{
      id: businessId
    }})
}
/*19 更新通知*/
function noticeNew ($router, businessId) {
  let userInfo = this.$localStorage.get('userInfo')
  let data = {
    loginId: "20160503155632000078",
    recUserId: userInfo.id,
    limit: 1,
    page: 1,
    pageSize: "20",
    msgId:businessId
  };
  this.fetchService.pageMsg(data).then((res) => {
    if(res.code !== 0){
      return
    }
    this.$store.state.noticeNewDetail = res.data[0];
    let params1 = {
      isRead: "1",
      recId: res.data[0].recId,
    };
    this.fetchService.updateBox(params1).then((res) => {
      if (res.code !== 0) {
        return;
      }
    });
    $router.push({ path: `/noticeNewDetail` });
  })
}
export default {
  redCloudNewsDetail,
  applicationList,
  groupInfoList,
  videoDetail,
  audioDetail,
  demonstration,
  onlineObservation,//示范点
  observe,//筑固工程-线上观摩
  sanhuiyikeDetail,//14 三会一课 15 主题党日 16 民主评议
  newTermReminderDetail,//17 换届提醒
  workingTrends,
  notifyDetail,
  url,
  branchSpace,//18 支部空间
  policyDocument,
  noticeNoticeDetail,
  noticeNew,// 首页通知
}
